<template>
	<view>
		<uni-forms ref="form" :modelValue="formData" validate-trigger="bind" class="margin-top">
			<view class="bg-white padding-lr">
				<uni-forms-item ref="input" name="email" label="邮箱">
					<input v-model="formData.email"  @blur="(e)=>$refs.input.onFieldChange($event.detail.value)" />
				</uni-forms-item>
			</view>
			<view class="bg-white padding-lr">
				<uni-forms-item ref="input" name="email" label="邮箱">
					<input v-model="formData.email"  @blur="(e)=>$refs.input.onFieldChange($event.detail.value)" />
				</uni-forms-item>
			</view>
			<view class="bg-white padding-lr">
				<uni-forms-item ref="input" name="email" label="邮箱">
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view class="uni-input">{{array[index]}}</view>
					</picker>
				</uni-forms-item>
			</view>
		</uni-forms>
		<view style="height: 142upx;"></view>
		<view class="padding bg-white fixed-bottom">
			<button type="primary" @click="submit">保存</button>
		</view>
	</view>
</template>

<script>
	import { getBuilding } from "@/api/building/index"
	export default {
		data() {
			return {
				formData: {}
			}
		},
		onLoad(e) {
			uni.setNavigationBarTitle({
				title: e.id ? '修改建筑物' : '新建建筑物'
			});
			if(e.id) {
				getBuilding(e.id).then(response => {
				  this.formData = response.data
				})
			}
		},
		methods: {
			submit() {
				// 在 onLoad 生命周期中，formData添加了一个 id 字段 ，此时这个字段是不参数校验的，所以结果中不返回
				// 在 validate(['id']) 方法中，指定第一个参数 ，即可返回id字段
				this.$refs.form.validate(['id'],(err,formData)=>{
					if(!err){
						console.log('success',formData)
					}
				})
			}
		}
	}
</script>

<style>
</style>
